<template>
  <div class="asset-form-page">
    <div class="page-header">
      <div class="header-left">
        <el-button text @click="handleBack">
          <el-icon><ArrowLeft /></el-icon>
          返回
        </el-button>
        <h2>{{ isEdit ? '编辑资产' : '新增资产' }}</h2>
      </div>
      <div class="header-actions">
        <el-button @click="handleSave">
          <el-icon><DocumentCopy /></el-icon>
          保存
        </el-button>
        <el-button type="primary" @click="handleSubmit">
          <el-icon><Check /></el-icon>
          提交
        </el-button>
      </div>
    </div>

    <el-card>
      <el-form :model="formData" label-width="120px">
        <el-divider content-position="left">基本信息</el-divider>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="资产编号">
              <el-input v-model="formData.code" placeholder="自动生成" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产名称">
              <el-input v-model="formData.name" placeholder="请输入资产名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="资产分类">
              <el-select v-model="formData.category" placeholder="请选择">
                <el-option label="办公设备" value="office" />
                <el-option label="生产设备" value="production" />
                <el-option label="IT设备" value="it" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资产价值">
              <el-input-number v-model="formData.value" :min="0" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { ArrowLeft, DocumentCopy, Check } from '@element-plus/icons-vue'

const route = useRoute()
const router = useRouter()
const isEdit = computed(() => route.name === 'AssetEdit')

const formData = reactive({
  code: '',
  name: '',
  category: '',
  value: 0
})

const handleBack = () => router.back()
const handleSave = () => ElMessage.success('保存成功')
const handleSubmit = () => {
  ElMessage.success('提交成功')
  router.push('/asset/list')
}
</script>

<style scoped>
.asset-form-page {
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.header-left h2 {
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 10px;
}
</style>

